<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/15
 * Time: 17:26
 */

class Login extends Controller
{
//    登录
    public function login(){
        if(input("post.")!=null){
            $data =input("post.");
            $yzm=$data["yzm"];
            $u_name=$data["u_name"];
            $u_password =sha1(md5($data["u_password"])."mingdaima");
//            if(!captcha_check($yzm)){
//                echo "<script>alert('验证失败')</script>";
//            }else{
            $result=Db::name('user')->where("user_name='$u_name'")->select();
            if ($result) {
                if($result[0]["user_dell"]==1){
                    if ($u_password == $result[0]["user_password"]) {
                        $_SESSION['u_name']=$u_name;
                        $_SESSION['u_r_id']=$result[0]["user_r_id"];

                            $this->success("登陆成功","admin/index/index",'',3);
                    } else {
                        echo "<script>alert('用户名或密码错误')</script>";
                    }
                }else{
                    $this->error("账号暂时不能登录，如需登录，请联系管理员！");
                }
            } else {
                $this->error("用户名或密码错误");
//                }
            }
        }
        return $this->fetch("login");
    }
//  退出
    public function loginout(){
        session_unset();
        session_destroy();
        $this->error("退出成功！","admin/login/login");
    }

    public  function jiekou(){
        $re=request()->param("open");
        if($re==111111){
            return 123456789;
        }else{
            return 9874563421;
        }
    }
}